package com.chenxbook.modules.boot.web.message;

import com.chenxbook.modules.boot.web.enums.GlobalResponseEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;


/**
 * Description
 * <br>  系统自定义controller返回包装类
 *
 * @author dongdongchen
 * @date 2020-02-25
 **/
@Data
public class ResponseMsg<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 请求状态（true:请求成功|false:请求失败）
     */
    private Boolean status = true;
    /**
     * 状态编码
     */
    private String code = GlobalResponseEnum.SUCCESS.getCode();
    /**
     * 返回描述信息
     */
    private String message = GlobalResponseEnum.SUCCESS.getMessage();
    /**
     * 自定义返回对象
     */
    @ApiModelProperty("data,自定义返回对象")
    private T data;

    public ResponseMsg(T data) {
        this.data = data;
    }

    public static ResponseMsg failure(String code, String message) {
        ResponseMsg responsemsg = new ResponseMsg();
        responsemsg.setStatus(Boolean.FALSE);
        responsemsg.setCode(code);
        responsemsg.setMessage(message);
        return responsemsg;
    }

    public ResponseMsg success(T data) {

        ResponseMsg responsemsg = new ResponseMsg();
        responsemsg.setStatus(Boolean.TRUE);
        responsemsg.setCode(GlobalResponseEnum.SUCCESS.getCode());
        responsemsg.setMessage(GlobalResponseEnum.SUCCESS.getMessage());
        responsemsg.setData(data);
        return responsemsg;
    }


    public static ResponseMsg<Void> success() {
        ResponseMsg responsemsg = new ResponseMsg();
        responsemsg.setStatus(Boolean.TRUE);
        responsemsg.setCode(GlobalResponseEnum.SUCCESS.getCode());
        responsemsg.setMessage(GlobalResponseEnum.SUCCESS.getMessage());
        return responsemsg;
    }

    public ResponseMsg() {
    }
}
